package com.wj.controller;


import com.wj.pojo.Admin;
import com.wj.pojo.RespBean;
import com.wj.pojo.Role;
import com.wj.service.IAdminService;
import com.wj.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wj
 * @since 2022-03-05
 */
@Api(tags = "操作员控制器")
@RestController
@RequestMapping("/system/admin")
public class AdminController {
    @Resource
    private IAdminService adminService;
    @Resource
    private IRoleService roleService;

    @ApiOperation("获取所有操作员")
    @GetMapping("/")
    public List<Admin> getAllAdmins(String keywords){
        return adminService.getAllAdmins(keywords);
    }

    @PutMapping("/")
    @ApiOperation("更改操作员")
    public RespBean updateAdmin(@RequestBody Admin admin){
        if (adminService.updateById(admin)){
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除操作员")
    public RespBean deleteAdmin(@PathVariable Integer id) {
        if (adminService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @ApiOperation("获取所有角色")
    @GetMapping("/roles")
    public List<Role> getAllRoles(){
        return roleService.list();
    }

    @ApiOperation("更改操作员角色")
    @PutMapping("/role")
    public RespBean updateAdminRole(Integer adminId,Integer[] rids){
        return adminService.updateAdminRole(adminId,rids);
    }

}
